{# Stalker Pyramid a Web Base Production Asset Management System
 Copyright (C) 2009-2014 Erkan Ozgur Yilmaz

 This file is part of Stalker Pyramid.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation;
 version 2.1 of the License.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#}
{% extends 'base.jinja2' %}

{# PRE-HEADER #}
{% block pre_header %}

    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/chosen.min.css") }}'/>
    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/datepicker.css") }}'/>
    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/bootstrap-timepicker.css") }}'/>
    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/daterangepicker.css") }}'/>
    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/colorpicker.css") }}'/>
    <link rel="stylesheet"
          href='{{ request.static_url("stalker_pyramid:static/ace/css/jquery-ui-1.10.3.custom.min.css") }}'/>
{#    <link rel="stylesheet"#}
{#          href='{{ request.static_url("stalker_pyramid:static/ace/css/bootstrap-editable.css") }}'/>#}

{% endblock pre_header %}

{# SIDEBAR #}
{% block sidebar %}

    {% if entity %}
        {% include 'sidebar.jinja2' %}
    {% endif %}

{% endblock sidebar %}

{# BREADCRUMBS #}
{% block breadcrumbs %}

    {% set page_title='Update' %}
    {% include 'breadcrumb/breadcrumbs.jinja2' %}

{% endblock breadcrumbs %}

{# PAGE-CONTENT #}
{% block page_content %}

    {% set page_title='Update' %}
    {% include 'page_header.jinja2' %}

    {% set group=entity %}

    <div class="row-fluid">
        <div class="widget-box span6">
            <div class="widget-header widget-header-small header-color-grey">
                <h4 class="smaller">
                    <i class="icon-info-sign"></i>
                </h4>

            </div>

            <div class="widget-body">
                <div class="widget-main">


                    <form id='group_update_form'
                          class='form-horizontal'
                          role='form'
                          method='post'>
                        <div class="row-fluid">
                             <div class="span3">
                            {% include 'components/avatar.jinja2' %}
                        </div>
                            <div class="span6">
                                {#Name #}
                                <div class="control-group">
                                    <label class="span4 control-label"
                                           for="group_name">Name</label>

                                    <div class="span8">
                                        <input id="group_name"
                                               name='name'
                                               type="text"
                                               class="form-control"
                                               value='{{ entity.name }}'
                                               required>
                                    </div>
                                </div>

                                {#Description #}
                                <div class='control-group'>
                                    <label class='span4 control-label'
                                           for='group_description'>Description</label>

                                    <div class='span8'>
                                        <textarea id="group_description"
                                                  name='description'
                                                  class="autosize-transition span12"
                                                  style="overflow: hidden;
                                         word-wrap: break-word;
                                         resize: horizontal;
                                         height: 50px;"
                                                >{{ entity.description }}</textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="space-15"></div>
                        </div>
                        <div class="row-fluid">

                            <h4 class="header blue bolder smaller">
                                Permissions</h4>
                            {#Permissions #}
                            {% set mode='Update' %}
                            {% set address=request.route_url('get_group_permissions', id=entity.id) %}
                            {% include 'group/list/list_group_permissions.jinja2' %}
                        </div>
                    </form>

                </div>

                <div class="row-fluid">
                    <div class="form-actions">

                        <button id='permissions_submit_button' type="button"
                                class='btn btn-success pull-right'>
                            <i class="icon-edit"></i> Update
                        </button>
                    </div>

                </div>
            </div>
        </div>
    </div>


{% endblock page_content %}

{# EXTRA-SCRIPTS #}
{% block extrascripts %}

    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/jquery-ui-1.10.3.custom.min.js") }}'></script>
    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/jquery.inputlimiter.1.3.1.min.js") }}'></script>

    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/additional-methods.min.js") }}'></script>
    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/jquery.validate.min.js") }}'></script>
    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/jquery.gritter.min.js") }}'></script>

    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/jquery.ui.touch-punch.min.js") }}'></script>
{#    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/x-editable/bootstrap-editable.min.js") }}'></script>#}
{#    <script src='{{ request.static_url("stalker_pyramid:static/ace/js/x-editable/ace-editable.min.js") }}'></script>#}


    <script type="text/javascript">


    var permissions_loaded = function () {


    }




    $(document).ready(function () {


        var submit_button = $('#permissions_submit_button');
        submit_button.on('click', function (e) {

            e.stopPropagation();
            e.preventDefault();
            submit_button.button('loading');

            var group_update_form = $("#group_update_form");

            bootbox.confirm(
                    '<div class="alert alert-info bigger-110">This will update the permission settings of {{ entity.name }}' +
                            '<br><br><strong>Are you sure?</strong></div>',
                    function (result) {
                        if (result) {
                            // get the ids and send it to the server

                            $.post('/groups/{{ entity.id}}/update', group_update_form.serialize() + '&' +
                                            $.param({ 'group_id': '{{ entity.id }}'})
                                    ).done(function (response_text) {
                                        bootbox.alert(response_text);
                                        window.location.assign('{{ came_from }}');
                                        submit_button.button('reset');
                                    }).fail(function (jqXHR) {
                                        bootbox.alert(jqXHR.responseText);
                                        submit_button.button('reset');
                                    });
                        }
                    }
            )
        });
    });

    </script>

{% endblock extrascripts %}

